package com.cg.serviceImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.cg.mapper.TbWeChatUserMapper;
import com.cg.pojo.TbWeChatUser;
import com.cg.pojo.TbWeChatUserExample;
import com.cg.service.TbWeChatUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: cg
 * @Date: Create IN 2017/6/21 17:19
 * @Email: cg_666666@163.com
 */
@Service(version="1.0.0")
public class TbWeChatUserServiceImpl implements TbWeChatUserService {
    @Autowired
    private TbWeChatUserMapper tbWeChatUserMapper;

    @Override
    public TbWeChatUser findbyOpenid(String openId) {
        TbWeChatUserExample example=new TbWeChatUserExample();
        TbWeChatUserExample.Criteria criteria = example.createCriteria();
        criteria.andOpenIdEqualTo(openId);
        List<TbWeChatUser> tbWeChatUsers = tbWeChatUserMapper.selectByExample(example);
        if(tbWeChatUsers!=null && tbWeChatUsers.size()>0){
            return tbWeChatUsers.get(0);
        }
        return null;
    }

    @Override
    @Transactional
    public int insert(TbWeChatUser tbWeChatUser) {
        int i = tbWeChatUserMapper.insert(tbWeChatUser);
        return i;
    }
}
